//===----------------------------------------------------------------------===//
//
// This source file is part of the Soto for AWS open source project
//
// Copyright (c) 2017-2021 the Soto project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Soto project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

// THIS FILE IS AUTOMATICALLY GENERATED by https://github.com/soto-project/soto/tree/main/CodeGenerator. DO NOT EDIT.

import SotoCore

/// Error enum for AppSync
public struct AppSyncErrorType: AWSErrorType {
    enum Code: String {
        case accessDeniedException = "AccessDeniedException"
        case apiKeyLimitExceededException = "ApiKeyLimitExceededException"
        case apiKeyValidityOutOfBoundsException = "ApiKeyValidityOutOfBoundsException"
        case apiLimitExceededException = "ApiLimitExceededException"
        case badRequestException = "BadRequestException"
        case concurrentModificationException = "ConcurrentModificationException"
        case graphQLSchemaException = "GraphQLSchemaException"
        case internalFailureException = "InternalFailureException"
        case limitExceededException = "LimitExceededException"
        case notFoundException = "NotFoundException"
        case unauthorizedException = "UnauthorizedException"
    }

    private let error: Code
    public let context: AWSErrorContext?

    /// initialize AppSync
    public init?(errorCode: String, context: AWSErrorContext) {
        guard let error = Code(rawValue: errorCode) else { return nil }
        self.error = error
        self.context = context
    }

    internal init(_ error: Code) {
        self.error = error
        self.context = nil
    }

    /// return error code string
    public var errorCode: String { self.error.rawValue }

    /// You do not have access to perform this operation on this resource.
    public static var accessDeniedException: Self { .init(.accessDeniedException) }
    /// The API key exceeded a limit. Try your request again.
    public static var apiKeyLimitExceededException: Self { .init(.apiKeyLimitExceededException) }
    /// The API key expiration must be set to a value between 1 and 365 days from creation (for CreateApiKey) or from update (for UpdateApiKey).
    public static var apiKeyValidityOutOfBoundsException: Self { .init(.apiKeyValidityOutOfBoundsException) }
    /// The GraphQL API exceeded a limit. Try your request again.
    public static var apiLimitExceededException: Self { .init(.apiLimitExceededException) }
    /// The request is not well formed. For example, a value is invalid or a required field is missing. Check the field values, and then try again.
    public static var badRequestException: Self { .init(.badRequestException) }
    /// Another modification is in progress at this time and it must complete before you can make your change.
    public static var concurrentModificationException: Self { .init(.concurrentModificationException) }
    /// The GraphQL schema is not valid.
    public static var graphQLSchemaException: Self { .init(.graphQLSchemaException) }
    /// An internal AWS AppSync error occurred. Try your request again.
    public static var internalFailureException: Self { .init(.internalFailureException) }
    /// The request exceeded a limit. Try your request again.
    public static var limitExceededException: Self { .init(.limitExceededException) }
    /// The resource specified in the request was not found. Check the resource, and then try again.
    public static var notFoundException: Self { .init(.notFoundException) }
    /// You are not authorized to perform this operation.
    public static var unauthorizedException: Self { .init(.unauthorizedException) }
}

extension AppSyncErrorType: Equatable {
    public static func == (lhs: AppSyncErrorType, rhs: AppSyncErrorType) -> Bool {
        lhs.error == rhs.error
    }
}

extension AppSyncErrorType: CustomStringConvertible {
    public var description: String {
        return "\(self.error.rawValue): \(self.message ?? "")"
    }
}
